﻿using System.Web.Script.Serialization;

namespace Xodeuz.SP.Common
{
    public static class ObjectExtensions
    {
        /// <summary>
        /// Is the current object null
        /// </summary>
        public static bool IsNull(this object data)
        {
            return data == null;
        }

        public static string ToStringSafe(this object data)
        {
            return data.IsNull() ? string.Empty : data.ToString();
        }

        public static string ToJSON(this object data)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            return serializer.Serialize(data);
        }
    }
}
